package com.why.controller;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.why.entity.Examination;
import com.why.service.ExaminationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * (Examination)表控制层
 *
 * @author makejava
 * @since 2023-05-25 20:19:59
 */
@RestController
@RequestMapping("/examination")
@CrossOrigin
public class ExaminationController {
    /**
     * 服务对象
     */
    @Autowired
    private ExaminationService examinationService;


    @DeleteMapping("/delete/{id}")
    private String delete(@PathVariable("id") Long id) {
        examinationService.removeById(id);
        return "success";
    }


    @GetMapping("/page")
    private Page<Examination> page(int page, int pageSize, String name) {
        Page pageInfo = new Page(page, pageSize);
        LambdaQueryWrapper<Examination> queryWrapper = new LambdaQueryWrapper<Examination>();
        queryWrapper.like(Examination::getExamname, name);
        queryWrapper.orderByDesc(Examination::getAddtime);
        examinationService.page(pageInfo, queryWrapper);
        return pageInfo;
    }

    @PostMapping("/update")
    private String update(@RequestBody Examination examination) {
        LambdaQueryWrapper<Examination> queryWrapper = new LambdaQueryWrapper<Examination>();
        queryWrapper.eq(Examination::getId, examination.getId());
        examinationService.update(examination, queryWrapper);
        return "success";
    }


    @GetMapping("/page1")
    private Page<Examination> page1(int page, int pageSize, String name) {
        Page pageInfo = new Page(page, pageSize);
        LambdaQueryWrapper<Examination> queryWrapper = new LambdaQueryWrapper<Examination>();
        queryWrapper.like(Examination::getExamname, name);
        queryWrapper.orderByDesc(Examination::getAddtime);
        queryWrapper.eq(Examination::getStatus, 1);
        examinationService.page(pageInfo, queryWrapper);
        return pageInfo;
    }


}

